job Echo(list inputs) {
  @{"echo %d" % [(int)inputs[0]]};
}

job Double(list inputs) {
  @{"echo -n %d" % [2*(int)inputs[0]]};
}

void main(list args) {
  //declare servers
  list first_servers = [["host"=>"localhost",
                         "user"=>"dummy",
                         "password"=>"dummypw"
                         ]];
  list second_servers = [["host"=>"localhost",
                          "user"=>"dummy2",
                          "password"=>"dummypw2"
                          ]];
  
  connect first_servers;
  
  list first_inputs;
  int i = 0;
  while (i < 5) {
    first_inputs = first_inputs + [[i]];
    i = i + 1;
  }
  
  list first_output;
  push Echo, null, first_inputs, first_output;
  waitall;

  list second_inputs;
  i = 0;
  while (i < length first_output) {
    second_inputs = second_inputs
      + [[ (int)((string)((map)(first_output[i]))["stdout"]) ]];
    i = i + 1;	
  }
  connect second_servers;
  
  list final_output;
  int x = push Double, null, second_inputs, final_output;
  waitall;
  
  for (int i = 0; i < length final_output; i = i + 1) {
    print "Final Result is: %s.\n" % [(string)((map)(final_output[i]))["stdout"]];
  }
}

